<?php

namespace app\pub\controller;

use app\common\facade\auth\Auth;
use app\common\service\Meituan;

class Union
{
    /**
     * 统一转化接口
     */
    public function index()
    {
        $conversion_url = input('conversion_url');

        if (strstr($conversion_url, 'meituan')) {
            return $this->meituan();
        }

        $service = new \api\channel\jutuike\Union();

        $act_id = input('act_id', 54);
        $mobile = input('mobile', '');

        $agent_id = Auth::agentId();
        $channel_id = Auth::channelId();
        $user_id = Auth::id();

        $res = $service->productUrl(compact('agent_id', 'user_id', 'channel_id', 'mobile'), $act_id);

        return success('', $res);
    }


    /**
     * 美团外卖
     * @return \think\response\Json
     * @throws \think\Exception
     */
    protected function meituan()
    {

        $meituan = new Meituan(Auth::agentId());

        $meituanRes = $meituan->generateLink([
            'user_id' => Auth::id(),
            'agent_id' => Auth::agentId(),
            'channel_id' => Auth::channelId(),
            'act_id' => input('act_id'),
            'from' => input('from')
        ]);


        $result = [];
        $result['long_h5'] = $meituanRes;
        $result['h5'] = $meituanRes;
        $result['we_app_info'] = [
            'app_id' => 'wxde8ac0a21135c07d',
            'page_path' => $meituanRes,
        ];

        return success('', $result);

    }


}